package dyyx;

import java.util.Map;
import java.util.Properties;

import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;

import dyyx.util.ConfigUtil;

public class AppUtil {
	
	public static final String TOPIC = "heartbeat_test_topic";
	
	public static final Producer<String,String> producer = createProducer();
	
	
	public static final  KafkaConsumer<String, String> manualCommitConsumer =  createManualCommitConsumer();
	public static final  KafkaConsumer<String, String> autoCommitConsumer = createAutoCommitConsumer();

	
	static {
		ManualCommitWorkThread manualCommitWorkThread = new ManualCommitWorkThread();
		manualCommitWorkThread.setName("manualCommitWorkThread");
		manualCommitWorkThread.start();
		
		AutoCommitWorkThread autoCommitWorkThread = new AutoCommitWorkThread();
		autoCommitWorkThread.setName("autoCommitWorkThread");
		autoCommitWorkThread.start();

		
	}
	
	
	
	public static Producer<String,String> createProducer() {		
		Properties props = new Properties();		
	    Map<String,String> config = ConfigUtil.getAllConfig();
	    config.forEach((k,v)->props.put(k, v));
		Producer<String, String> producer = new KafkaProducer<String, String>(props);	
		return producer;
	}
	
	
	public static KafkaConsumer<String, String> createAutoCommitConsumer() {		
		
		return null;
	}
	
    public static KafkaConsumer<String, String> createManualCommitConsumer() {		
		
		return null;
	}
    
    
    private static final class ManualCommitWorkThread extends Thread{
    	
    	@Override
    	public void run() {
    		
    	}
    	// end run
    }
    
    
    private static final class AutoCommitWorkThread extends Thread{
    	
    	@Override
    	public void run() {
    		
    	}
    	// end run
    }
	

	
}
